//
//  IdTypePickView.swift
//  旅航ios
//
//  Created by tulip on 2021/6/24.
//

import UIKit

class IdTypePickView: UIView,UIPickerViewDelegate,UIPickerViewDataSource {
    
    
    var myidType:(((Int,String))->Void)?
    var idType=(1,"身份证")
    var mbtn:UIButton!

    var arr:Array<String>!
    var picker:UIPickerView!
    var close:UIButton!
    var currentMapStr:String!
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.frame=CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)
        self.backgroundColor=UIColor.black.withAlphaComponent(0.7)
        let peopleview=UIView.init(frame: CGRect(x: 0, y: SCREEN_HEIGHT-340-BottomSpaceHeigh, width: SCREEN_WIDTH, height: 340))
        self.addSubview(peopleview)
        
        peopleview.backgroundColor=UIColor.white
        let title=UILabel(frame: CGRect(x: 15, y: 15, width: 200, height: 15))
        title.textColor=UIColor.init(hexString: "545454")
        title.font=UIFont.boldSystemFont(ofSize: 15)
        title.text="请选择身份证件类型"
        peopleview.addSubview(title)
        
        
        
        close=UIButton.init(frame: CGRect(x: SCREEN_WIDTH-43, y: 0, width: 43, height: 43))
        close.setImage(UIImage(named: "关闭"), for: .normal)
        close.addTarget(self, action: #selector(closeView), for: .touchUpInside)
        peopleview.addSubview(close)
        
        let line1=UIView.init(frame: CGRect(x: 0, y: 50, width: SCREEN_WIDTH, height: 1))
        line1.backgroundColor=UIColor.init(hexString: "efefef")
        peopleview.addSubview(line1)
       
        //1身份证 2护照 3军人证 4回乡证 5台胞证 6外国人永久居留证 99 其他
        arr=["身份证","护照","军人证","回乡证","台胞证","外国人永久居留证","其他"]
        
        //时间 pick viwe
        picker=UIPickerView.init(frame: CGRect(x: 0, y: 60, width: SCREEN_WIDTH, height: 170))
        picker.delegate=self
        picker.dataSource=self
        picker.selectRow(0,inComponent:0,animated:true)
        peopleview.addSubview(picker)
        picker.backgroundColor=UIColor.white
        
        
        //post btn
        mbtn=UIButton.init(frame: CGRect(x: 15, y: 340-90, width: SCREEN_WIDTH-30, height: 49))
        mbtn=gradientColor(colo1: "fe4f4b", colo2: "ff874a", view: mbtn, width: SCREEN_WIDTH-30) as! UIButton
        peopleview.addSubview(mbtn)
        mbtn.setTitle("确认", for: .normal)
        mbtn.setTitleColor(UIColor.white, for: .normal)
        mbtn.layer.cornerRadius=5
        mbtn.addTarget(self, action: #selector(postChoose), for: .touchUpInside)
        mbtn.layer.masksToBounds=true
      
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        1
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        arr.count
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        
        let titel = arr[row] 
        return titel
        
        
    }
    func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
        50
    }
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        let xrow=pickerView.selectedRow(inComponent: 0)
        //1身份证 2护照 3军人证 4回乡证 5台胞证 6外国人永久居留证 99 其他
        switch xrow {
        case 0:
            idType=(1,"身份证")
        case 1:
            idType=(2,"护照")
        case 2:
            idType=(3,"军人证")
        case 3:
            idType=(4,"回乡证")
        case 4:
            idType=(5,"台胞证")
        case 5:
            idType=(6,"外国人永久居留证")
        case 6:
            idType=(99,"其他")
  
        default:
            break
        }
        
    }
    
    
    @objc func closeView(){
        self.removeFromSuperview()
    }
    
    @objc  func postChoose(){
        self.removeFromSuperview()
        if (myidType != nil) {
            self.myidType!(idType)
        }

     
    }
}



